﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyButton{
    public bool isPressing = false;
    public bool onPressed = false;
    public bool onReleased = false;
    public bool isExtending = false;
    public bool isDelaying = false;

    [Header("=== 设置 ===")]
    public float extendingDuration = 0.15f;
    public float delayDuration = 0.15f;

    private bool currentState = false;
    private bool lastState = false;

    private MyTimer extTimer = new MyTimer();
    private MyTimer delTimer = new MyTimer();
    public void Tick(bool input)
    {
        extTimer.Tick();
        delTimer.Tick();

        currentState = input;

        isPressing = currentState;

        onPressed = false;
        onReleased = false;
        if (currentState != lastState)
        {
            if(currentState == true)
            {
                onPressed = true;
                StartTimer(delTimer, delayDuration);
            }
            else
            {
                onReleased = true;
                StartTimer(extTimer, extendingDuration);
            }
        }
        lastState = currentState;

        isExtending = (extTimer.state == MyTimer.STATE.RUN) ? true : false;
        isDelaying = (delTimer.state == MyTimer.STATE.RUN) ? true : false;
    }
    private void StartTimer(MyTimer timer,float duration)
    {
        timer.duration = duration;
        timer.Go();
    }
}
